﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.ComponentModel.Compiler;

namespace OpenComposite.Workflow
{
    public class NotificationActivityValidator : ActivityValidator
	{
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);

			if ( obj is NotificationActivity ) {
				NotificationActivity activity = obj as NotificationActivity;

				if ( activity.Parent != null ) {
					if ( string.IsNullOrEmpty(activity.NotificationHost)||
						 string.IsNullOrEmpty(activity.NotificationSender)) {
						errors.Add(new ValidationError(
							"Missing SMTP Properties!", 501));
					}
					if ( activity.Notification == null ||
						 string.IsNullOrEmpty(activity.Notification.Message) ||
						 string.IsNullOrEmpty(activity.Notification.Recipient) ||
						 string.IsNullOrEmpty(activity.Notification.Subject) ) {
						errors.Add(new ValidationError(
							"Missing Notification Configuration!", 501));
					}
				}
			}

            return errors;
        }
	}
}
